package com.resou.reader.discovery.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.resou.reader.R;
import com.resou.reader.api.entry.ActivityBean;
import com.resou.reader.api.entry.DisCoveryBean;
import com.resou.reader.utils.UIHelper;

import java.util.List;

public class DisCoveryAdapter extends BaseQuickAdapter<DisCoveryBean, BaseViewHolder> {
    ActivityBean activityBean;

    public DisCoveryAdapter(int layoutResId, @Nullable List<DisCoveryBean> data) {
        super(layoutResId, data);
    }

    public DisCoveryAdapter(@Nullable List<DisCoveryBean> data) {
        super(data);
    }

    @Override
    protected void convert(BaseViewHolder helper, DisCoveryBean item) {
        helper.addOnClickListener(R.id.llContent);
        ImageView ic_titleIcon = helper.getView(R.id.ic_titleIcon);
        LinearLayout llContent = helper.getView(R.id.llContent);
        if (item.isShowLocal()) {
            Glide.with(mContext).load(item.getLocalUrl()).into(ic_titleIcon);
        } else {
            Glide.with(mContext).load(item.getUrl()).into(ic_titleIcon);
        }
        helper.setText(R.id.tvTitles, item.getName() + "");
        if (item.getId() == 5) {
            llContent.setPadding(0, 0, 0, UIHelper.dip2px(mContext, 5));
        } else {
            llContent.setPadding(0, 0, 0, UIHelper.dip2px(mContext, 1));
        }
    }

    /**
     * @param activityBean
     */
    public void updataActivityInfo(ActivityBean activityBean) {
        this.activityBean = activityBean;
        notifyDataSetChanged();
    }
}
